package com.aqs;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;

/**
 * @author Zhang Zhe
 * @since 2020年02月18日 15:19:00
 */
public class Zlock implements Lock {

	Integer i = 0;

	@Override
	public void lock() {
		synchronized (this){
			while (i!=0){
				try {
					this.wait();
				} catch (InterruptedException e) {
					System.out.println("lock:"+e.getMessage());;
				}
			}
			i = 1;
		}
	}

	@Override
	public void lockInterruptibly() throws InterruptedException {

	}

	@Override
	public boolean tryLock() {
		return false;
	}

	@Override
	public boolean tryLock(long time, TimeUnit unit) throws InterruptedException {
		return false;
	}

	@Override
	public void unlock() {
        synchronized (this){
			try {
				i = 0;
				this.notifyAll();
			} catch (Exception e) {
				e.printStackTrace();
			}
        }
	}

	@Override
	public Condition newCondition() {
		return null;
	}
}
